import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/handle/xindong_user_handle.dart';
import 'package:xindong/routes/user/visit/xindong_visit_list_container.dart';
import 'package:xindong/routes/user/visit/xindong_visit_vm.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/common/xindong_tab_indicator.dart';

class XinDongVisitYeMian extends StatefulWidget {
  const XinDongVisitYeMian({super.key});

  @override
  State<XinDongVisitYeMian> createState() => _XinDongVisitYeMianState();
}

class _XinDongVisitYeMianState extends State<XinDongVisitYeMian> {
  final tabBars = const [Tab(text: "谁看过我"), Tab(text: "我看过谁")];
  final String kControllerTagVisitMe = "kControllerTagVisitMe";
  final String kControllerTagMineVisit = "kControllerTagFollow";
  final XinDongVisitVM visitMeVM = XinDongVisitVM(type: VisitType.visitMe);
  final XinDongVisitVM mineVisitVM = XinDongVisitVM(type: VisitType.mineVisit);

  // TabView
  List<Widget> tabBarViews() {
    return [
      XinDongVisitListContainer(
        controllerTag: kControllerTagVisitMe,
        emptyTips: '最近没有访客，多活跃提高曝光度～',
      ),
      XinDongVisitListContainer(
        controllerTag: kControllerTagMineVisit,
        emptyTips: '去浏览更多的人吧',
      ),
    ];
  }

  @override
  void initState() {
    super.initState();

    // tag标记同一个控制器名称，区分不同实例
    Get.create(() => visitMeVM, tag: kControllerTagVisitMe, permanent: false);
    Get.create(() => mineVisitVM, tag: kControllerTagMineVisit, permanent: false);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: XinDongAppBar("我的访客"),
      body: DefaultTabController(
        length: tabBars.length,
        child: Column(
          children: [
            Container(
              height: 44.0,
              alignment: Alignment.center,
              child: TabBar(
                indicator: const XinDongTabIndicator(color: DZColors.mainColor),
                indicatorSize: TabBarIndicatorSize.label,
                labelPadding: const EdgeInsets.only(left: 16, right: 5),
                labelColor: DZColors.titleColor,
                unselectedLabelColor: DZColors.contentColor,
                labelStyle: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
                unselectedLabelStyle: const TextStyle(fontSize: 16),
                tabs: tabBars,
              ),
            ),
            Expanded(
              child: TabBarView(children: tabBarViews()),
            ),
          ],
        ),
      ),
    );
  }
}
